import time

from tools.base_page import BasePage


class Zxx_Base(BasePage):
    def make_study_room(self):
        make = ('id', 'studyRoomSignInBtn')
        make_room = ('id', 'item_base_reserve')
        self.find(make).click()
        self.elements(make_room)[0].click()

    def room_fill_in_message(self, name_text, phone_text):
        make_num_room = ('id', 'choiceRoom')
        seart_time = ('id', 'reserveRoomStartTimeTitle')
        end_time = ('id', 'reserveRoomEndTimeArrow')
        seat_num = ('id', 'choiceNumberTitle')
        name = ('id', 'serUserNameEdt')
        phone = ('id', 'setUserPhoneEdt')
        finish = ('xpath', '//*[@text="完成"]')

        click_list = [make_num_room, seart_time, end_time, seat_num]
        for num in click_list:
            self.find(num).click()
            time.sleep(2)
            self.find(finish).click()
            time.sleep(2)
        time.sleep(2)
        self.find(name).send_keys(name_text)
        self.find(phone).send_keys(phone_text)

    def submit_order(self):
        submit = ('id', 'orderConfirmBtn')
        title_text = ('id', 'title_text')
        self.find(submit).click()
        if self.is_element(title_text).click():
            self.page(self.index)
            return True
        else:
            self.page(self.index)
            return False
